<template>
  <view>
    <view class="goods-list">
      <view class="goods_list-item">
        <!-- 左边盒子 -->
        <view class="goods_list-item-left-box">
          <radio :checked="goods.goods_state" @click="radioClickHandler" color="#c00000" v-if="showRadio"></radio>
          <image :src="goods.goods_small_logo || defaultImg"></image>
        </view>
        <!-- 右边盒子 -->
        <view class="goods_list-item-right-box">
          <text class="goods-name"> {{goods.goods_name}}</text>
          <view class="goods-info-box">
            <text class="goods-price"> ${{goods.goods_price | toFixed}}</text>
            <uni-number-box v-if="showButton" @change="numberChangeHandle" :value=goods.goods_count :min="1" :max="9"></uni-number-box>
          </view>

        </view>
      </view>
    </view>


  </view>
</template>

<script>
  export default {
    name: "my-goods",
    props: {
      goods: {
        type: Object,
        dafault: {}
      },
      showRadio: {
        type: Boolean,
        dafault: false
      },
      showButton: {
        type: Boolean,
        dafault: false
      }
    },
    data() {
      return {
        defaultImg: 'https://file.moyublog.com/d/file/2022-03-15/x4hi3xasuoq.jpg'
      };
    },
    filters: {
      toFixed(num) {
        return Number(num).toFixed(2)
      }
    },
    methods: {
      radioClickHandler(e) {
        this.$emit('radio-change', {
          goods_id: this.goods.goods_id,
          goods_state: !this.goods.goods_state
        })
      },
      numberChangeHandle(e){
       
        this.$emit('number-change', {
          goods_id: this.goods.goods_id,
          goods_count:e
        })
      }
    }
  }
</script>

<style lang="scss">
  .goods-list {
    .goods_list-item {
      padding-bottom: 5px;
      border: 2px solid #efefef;
      display: flex;

      // justify-content: space-between;
      .goods_list-item-left-box {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 5px;

        image {
          width: 100px;
          height: 100px;
          display: block;
        }
      }

      .goods_list-item-right-box {
        padding: 0px 5px;
        display: flex;
        justify-content: space-between;
        flex-direction: column;

        .goods-name {
          font-size: 12px;
        }

        .goods-info-box {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .goods-price {
            font-size: 18px;
            color: #c00000;
          }


        }

      }
    }
  }
</style>